package com.xi.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xi.mapper.ReservationMapper;
import com.xi.pojo.PageResult;
import com.xi.pojo.Reservation;
import com.xi.pojo.ReservationQueryParam;
import com.xi.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReservationServiceImpl implements ReservationService {
    @Autowired
    private ReservationMapper reservationMapper;

    /*
     * 分页查询预约信息
     * */
    @Override
    public PageResult page(ReservationQueryParam reservationQueryParam) {
        // 1.设置分页参数
        PageHelper.startPage(reservationQueryParam.getPage(), reservationQueryParam.getPageSize());

        // 2.执行查询
        List<Reservation> rows = reservationMapper.list(reservationQueryParam);

        // 3.解析查询结果，并封装
        Page<Reservation> p = (Page<Reservation>) rows;
        return new PageResult<>(p.getTotal(), p.getResult());
    }
}
